package com.yl.applicationsecurity.controller;

import com.yl.applicationsecurity.pojo.Assets;
import com.yl.applicationsecurity.pojo.Result;
import com.yl.applicationsecurity.service.AlarmRecordService;
import com.yl.applicationsecurity.utils.ScoreCalculatorUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;

/**
 * @author 鹤仙问鹿仙
 * @program: Application-security
 * @description:
 * @date 2025-04-30 09:33:37
 */
@RestController
@RequestMapping("/alarmRecord")
public class AlarmRecordController {

    @Autowired
    private AlarmRecordService alarmRecordService;

    @RequestMapping("/getData")
    public Result getData() {
        alarmRecordService.getDataSgmSafeRiskToAlarmRecord(LocalDateTime.now());
        return  Result.error("添加失败");


    }

    @RequestMapping("/overdueDateReport")
    public Result getDataReport(String[] nationSelect,Date statisticsDate) {
        HashMap<String,Object> map = alarmRecordService.getDataReportSgmSafeRiskToAlarmRecord(nationSelect, statisticsDate,false);
        return Result.success(map);
    }


    @GetMapping("/overdueDateReport2")
    public Result getDataReport(String date) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date statisticsDate = formatter.parse(date);
        String[] nationSelect = new String[]{};
        HashMap<String,Object> map = alarmRecordService.getDataReportSgmSafeRiskToAlarmRecord(nationSelect, statisticsDate,true);
        Long momentCount = (Long)map.get("momentCount"); //当月告警总数量
        Long momentoverdueDateCount = (Long)map.get("momentoverdueDateCount"); //获取当月超期告警数量
        double percentage = 100-(momentoverdueDateCount * 100.0) / momentCount;
        map.put("percentage",percentage+"%");
        int grade = ScoreCalculatorUtil.calculateScore(momentoverdueDateCount.intValue(),momentCount.intValue());
        map.put("grade",grade);
        map.remove("countDetails");
        map.remove("overdueDateCountDetails");
        return Result.success(map);
    }






}

